package dao;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Component;

import support.GridResult;
import dao.support.sql.SqlObject;
import model.data.Product;
import model.data.Stock;
import model.data.Storehouse;

@Component
public class StockDao extends BaseDao {
	public void stock_add(Stock stock)
	{
		this.create(stock);
	}
	public void stock_delete(String stock_id)
	{
		Object []list = JSONArray.fromObject(stock_id).toArray();
		for(Object obj : list)
		{
			String s = obj.toString();
			this.delete(Integer.parseInt(s), Stock.class);
		}
	}
	public Stock stock_foundbyid(String stock_id)
	{
		int id = Integer.parseInt(stock_id);
		return (Stock) super.loadById(id, Stock.class);
	}
	public void stock_update(Stock stock)
	{
		this.update(stock);
	}
	public String stock_query(SqlObject so)
	{
		Object obj = this.querySQLRead(so.getSqlCount()).get(0).get("c");
		int total = Integer.parseInt(obj.toString());
		return new GridResult(so.getPage(), (total-1)/so.getRows()+1, total, this.querySQLRead(so.getSqlRows())).toString();
	}
	public Product stock_findproduct(SqlObject so)
	{
		
		return null;
	}
	public Storehouse storehouse_foundbyid(String storehouse_id)
	{
		int id = Integer.parseInt(storehouse_id);
		return (Storehouse) super.loadById(id, Storehouse.class);
	}
}
